<template>
	<view class="app-container">
		<view class="title">
			密码找回
		</view>
		<view class="form">
			<view class="item">
				<input v-model="form.username" type="text"  placeholder="注册手机"/>
				<view class="send-code" @click="sendCode">发送验证码</view>
			</view>
			<view class="item">
				<input v-model="form.code" type="text" placeholder="短信验证码"/>
			</view>
			<view class="item">
				<input v-model="form.password" type="password" placeholder="新密码"/>
			</view>
		</view>
		<view class="btn">
			<button type="primary" @click="handleSubmit">提 交</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form:{
					username:'',
					code:'',
					password:''
				}
			}
		},
		methods: {
			handleSubmit() {
				let username = this.form.username.trim()
				let code = this.form.code.trim()
				let password = this.form.password.trim()
				if(!username || !code || !password){
					return uni.showToast({
						icon:'none',
						title:'请填写完整'
					})
				}
				const reg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
				
				if(!reg.test(username)){
					return uni.showToast({
						icon:'none',
						title:'手机格式错误'
					})
				}
				
				if(code != '666666') {
					return uni.showToast({
						icon:'none',
						title:'短信验证码错误'
					})
				}
				
				uni.showToast({
					title:'找回成功'
				})
				setTimeout(() => {
					uni.navigateBack()
				}, 500)
			},
			goPage(url) {
				uni.navigateTo({
					url:`/pages/login/${url}`
				})
			},
			sendCode() {
				let username = this.form.username.trim()
				const reg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/

				if(!reg.test(username)){
					return uni.showToast({
						icon:'none',
						title:'手机格式错误'
					})
				}
				uni.showToast({
					title:'验证码发送成功'
				})
			}
		}
	}
</script>

<style>
	.title{
		font-weight: bold;
		font-size: 24px;
		color: #666;
		padding: 10px 20px;
	}

	.item{
		display: flex;
		border-bottom: 2px solid #eee;
		margin: 10px 20px;
		padding: 10px;
		justify-content: space-between;
		align-items: center;
	}
	.send-code {
		height: 30px;
		line-height: 18px;
		padding: 5px;
		border: 1px solid #999;
		border-radius: 5px;
		box-sizing: border-box;
		color: #666;
	}
	.btn{
		padding: 10px 20px;
	}
	.btn-text{
		display: flex;
		justify-content: center;
	}
	.btn-text view{
		padding: 10px;
		color: #007aff;
	}
</style>
